package com.shrcl.engineerprocess.domain.impl;

import com.google.common.base.Objects;
import com.shrcl.engineerprocess.domain.CorpWeChatUser;
import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.impl.EngineerImpl;
import com.shrcl.engineerprocess.domain.proxy.CorpWeChatUserProxy;
import com.uniquesoft.uidl.validation.Validates;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Exceptions;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("CORPWECHATUSER_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "corpwechatuser")
public class CorpWeChatUserImpl extends BaseModelObject implements CorpWeChatUser {
  public CorpWeChatUserImpl() {
    super();
  }
  
  @JoinColumn(name = "engineer_id")
  @ManyToOne(targetEntity = EngineerImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private Engineer engineer;
  
  public Engineer getEngineer() {
    return this.engineer;
  }
  
  public CorpWeChatUser setEngineer(final Engineer engineer) {
    this.engineer = engineer;
    return this;			
    
  }
  
  private String wechatid;
  
  public String getWechatid() {
    return this.wechatid;
  }
  
  public CorpWeChatUser setWechatid(final String wechatid) {
    this.wechatid = wechatid;
    return this;			
    
  }
  
  private String wechatuserid;
  
  public String getWechatuserid() {
    return this.wechatuserid;
  }
  
  public CorpWeChatUser setWechatuserid(final String wechatuserid) {
    this.wechatuserid = wechatuserid;
    return this;			
    
  }
  
  private String name;
  
  public String getName() {
    return this.name;
  }
  
  public CorpWeChatUser setName(final String name) {
    this.name = name;
    return this;			
    
  }
  
  private Date registerDate;
  
  public Date getRegisterDate() {
    return this.registerDate;
  }
  
  public CorpWeChatUser setRegisterDate(final Date registerDate) {
    this.registerDate = registerDate;
    return this;			
    
  }
  
  private Boolean excluded = Boolean.valueOf(true);
  
  public Boolean getExcluded() {
    return this.excluded;
  }
  
  public CorpWeChatUser setExcluded(final Boolean excluded) {
    this.excluded = excluded;
    return this;			
    
  }
  
  public String updateName() {
    String _xblockexpression = null;
    {
      String _plus = ("[WeChatUser.updateName]wexinid =" + this.wechatid);
      InputOutput.<String>println(_plus);
      boolean _equals = ((this.excluded).booleanValue() == false);
      if (_equals) {
        try {
          InputOutput.<String>println(this.name);
        } catch (final Throwable _t) {
          if (_t instanceof Exception) {
            final Exception e = (Exception)_t;
            this.name = "\u672A\u77E5";
            e.printStackTrace();
          } else {
            throw Exceptions.sneakyThrow(_t);
          }
        }
      }
      _xblockexpression = (this.name);
    }
    return _xblockexpression;
  }
  
  public void sendMessage(final String subject, final String body) {
    boolean _equals = ((this.excluded).booleanValue() == false);
    if (_equals) {
      InputOutput.<String>println("===========>TODO: WECHATUSER.edl sendmessge ...");
    }
  }
  
  public void checkValid() {
    boolean _notEquals = (!Objects.equal(this.engineer, null));
    Validates.Assert(_notEquals, "\u5DE5\u7A0B\u5E08\u4E0D\u80FD\u4E3A\u7A7A");
  }
  
  public static CorpWeChatUser create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.CorpWeChatUser corpWeChatUser = new com.shrcl.engineerprocess.domain.impl.CorpWeChatUserImpl(
    );
    objectFactory.create(corpWeChatUser);
    return corpWeChatUser;			
    
  }
  
  public static CorpWeChatUser createCorpWeChatUserImpl(final IObjectFactory objectFactory, final Procedure1<CorpWeChatUser> init) {
    com.shrcl.engineerprocess.domain.CorpWeChatUser corpWeChatUser = new com.shrcl.engineerprocess.domain.impl.CorpWeChatUserImpl(
    );
    objectFactory.create(corpWeChatUser);
    init.apply(corpWeChatUser);
    
    return corpWeChatUser;			
    
  }
  
  public CorpWeChatUserProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.CorpWeChatUserProxy proxy = new com.shrcl.engineerprocess.domain.proxy.CorpWeChatUserProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
